<template>
  <MrCustom bg-color="bg-gradual-blue " is-back>
    <template #backText>
      返回
    </template>
  </MrCustom>
  <view class=" bg-white radius flex flex-direction padding justify-between">
    <uni-forms ref="form" border :rules="rules" :modelValue="formData" label-position="left" label-align="right"
               label-width="50px">
      <uni-forms-item required label="姓名" name="name">
        <uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名"/>
      </uni-forms-item>
      <uni-forms-item label="性别" required>
        <uni-data-checkbox v-model="formData.sex" :localdata="sexs"/>
      </uni-forms-item>
      <uni-forms-item label="医院" required>
        <HospitalPopupSelect v-model:hospital="formData.hospital"></HospitalPopupSelect>
      </uni-forms-item>
      <uni-forms-item label="部门" required>
        <DepartmentSelect v-model:department="formData.department"></DepartmentSelect>
      </uni-forms-item>
      <uni-forms-item label="手机号码" required>
        <uni-easyinput v-model="formData.phone" placeholder="请输入手机号码"></uni-easyinput>
      </uni-forms-item>
    </uni-forms>
  </view>
  <view class="text-center padding text-gray text-df" style="height: 15vh">
    平台将会收集信息用于确认服务对象
  </view>
  <view class="cu-bar foot  bg-white" style="z-index: 5">
    <view class="flex flex-sub padding-lr flex-direction">
      <button class="cu-btn lg bg-gradual-blue" @click="submitForm">提交</button>
    </view>
  </view>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import {useUserStore,} from '@/store'
import api from '@/api'
import DepartmentSelect from './components/DepartmentSelect.vue'
import MrCustom from "@/components/common/MrCustom.vue";
import HospitalPopupSelect from "@/components/common/select/HospitalPopupSelect.vue";

const userStore = useUserStore()
const userInfo = userStore.userInfo
const formData = ref({
  username: '',
  avatar:'',
  name: '',
  sex: '',
  department: '',
  phone: '',
  hospital: '',
})
const form = ref()
const rules = ref()
const sexs = ref([{
  text: '男',
  value: '男'
}, {
  text: '女',
  value: '女'
}],)
const submitForm = () => {
  formData.value.username = userInfo.username
  formData.value.avatar = userInfo.avatar
  api.nurse.create(formData.value).then((res => {
    if (res.data.code === 0) {
      uni.switchTab({
        url: '/pages/user/mine/mine',
        success: () => {
          uni.showToast({
            icon: 'success',
            title: res.data.msg,
          })
        }
      })
    }
  }))
}
</script>

<style>
</style>
